#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   convert_csv_to_jsonL.py    
@Contact :   fengfeng.qiu@amh-group.com

@Modify Time      @Author    
------------      -------    
2022/7/25 16:40   qiufengfeng      
'''
import pandas as pd
import requests
import json

file = '20220720_隐私号解析后数据.csv'


def get_result(item):
    url = "https://qa.amh-group.com/panamera/quark/quark"
    packageType = ""
    header = {
        'Content-Type': "application/json"
    }
    post_data = {
        'text': item['text']
    }

    result = 0
    try:
        req = requests.post(url, data=json.dumps(post_data), headers=header)
        if req.json():
            return req.json()['data']['driverTargetPrice'],req.json()['data']['driverPriceConfidence'],req.json()['data']['shipperTargetPrice'],req.json()['data']['shipperPriceConfidence']
    except Exception as e:
        print(e)
    return "","","",""

df = pd.read_csv(file)
df = df[:200]
df['driverTargetPrice'],df['driverPriceConfidence'],df['shipperTargetPrice'],df['shipperPriceConfidence'] = zip(*df.apply(get_result,axis=1))

df.to_json("doccao.jsonL",orient="records",lines=True)




